// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
//

#pragma once

#include <kllm/proto/interface.struct.pb.h>
#include <nlohmann/json.hpp>
#include <kllm/core/params.h>

namespace kllm {

    inline void set_response_ok(KaiResponse &res) {
        res.mutable_status()->set_code(0);
        res.mutable_status()->set_errmsg("ok");
    }

    KaiPromptsType detect_prompt_type(const KaiPrompts & prompts);

    bool is_string(const KaiPrompts & prompts);

    bool is_number(const KaiPrompts & prompts);

    bool is_string_number_mix(const KaiPrompts & prompts);

    bool is_list(const KaiPrompts & prompts);

    bool is_string_list(const KaiPrompts & prompts);

    bool is_number_list(const KaiPrompts & prompts);

    bool has_list_value(const KaiPrompts & prompts);

    bool extract_number_list(const KaiPrompts & prompts, std::vector<int32_t> &ret);

    bool extract_number_list(const PromptsValue & prompts, std::vector<int32_t> &ret);

    PromptsValueType detect_prompt_type(const PromptsValue & prompts);

    PromptsValueType detect_prompt_list_type(const PromptsValue & prompts);

    // ["string"] -> [["string]]
    // ["stirng", n1] -> [["string", n1]]
    // ["string", n1, [n1, "string"], n2] -> [["stirng"], [n1], [n1, "string"], [n2]]
    bool flatten_to_mix_lists(const KaiPrompts & prompts, std::vector<PromptsValue> &ret);

}